import 'package:flutter/material.dart';

class AppTheme {
  // 主题色列表 - 优化色彩搭配
  static const List<Color> colorSeeds = [
    Color(0xFF2196F3), // 蓝色
    Color(0xFF9C27B0), // 紫色
    Color(0xFF4CAF50), // 绿色
    Color(0xFFFF9800), // 橙色
    Color(0xFFE91E63), // 粉色
    Color(0xFF607D8B), // 蓝灰色
    Color(0xFF009688), // 青色
    Color(0xFFFF5252), // 红色
  ];
  
  // 获取亮色主题
  static ThemeData lightTheme({int colorSeedIndex = 0}) {
    final colorSeed = colorSeeds[colorSeedIndex % colorSeeds.length];
    
    return ThemeData(
      useMaterial3: true,
      colorScheme: ColorScheme.fromSeed(
        seedColor: colorSeed,
        brightness: Brightness.light,
      ),
      // 应用栏主题
      appBarTheme: AppBarTheme(
        centerTitle: true,
        elevation: 2,
        shadowColor: Colors.black.withOpacity(0.1),
        backgroundColor: Colors.white,
        foregroundColor: colorSeed,
        iconTheme: IconThemeData(color: colorSeed),
        titleTextStyle: TextStyle(
          fontSize: 18,
          fontWeight: FontWeight.bold,
          color: colorSeed,
        ),
      ),
      // 卡片主题
      cardTheme: CardThemeData(
        elevation: 3,
        shadowColor: Colors.black.withOpacity(0.2),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(16),
        ),
        clipBehavior: Clip.antiAlias,
      ),
      // 按钮主题
      elevatedButtonTheme: ElevatedButtonThemeData(
        style: ElevatedButton.styleFrom(
          padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10),
          ),
          elevation: 2,
          shadowColor: colorSeed.withOpacity(0.3),
        ),
      ),
      // 文本按钮主题
      textButtonTheme: TextButtonThemeData(
        style: TextButton.styleFrom(
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(8),
          ),
        ),
      ),
      // 输入框主题
      inputDecorationTheme: InputDecorationTheme(
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(10),
          borderSide: BorderSide(color: Colors.grey.shade300),
        ),
        enabledBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(10),
          borderSide: BorderSide(color: Colors.grey.shade300),
        ),
        focusedBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(10),
          borderSide: BorderSide(color: colorSeed, width: 2),
        ),
        filled: true,
        fillColor: Colors.grey.shade50,
        contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
        hintStyle: TextStyle(color: Colors.grey.shade500),
      ),
      // 文本主题 - 使用仿宋字体
      textTheme: const TextTheme(
        titleLarge: TextStyle(fontWeight: FontWeight.bold, fontSize: 22, fontFamily: 'FangSong', fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312']),
        titleMedium: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, fontFamily: 'FangSong', fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312']),
        titleSmall: TextStyle(fontWeight: FontWeight.bold, fontSize: 16, fontFamily: 'FangSong', fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312']),
        bodyLarge: TextStyle(fontSize: 16, fontFamily: 'FangSong', fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312']),
        bodyMedium: TextStyle(fontSize: 14, fontFamily: 'FangSong', fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312']),
        bodySmall: TextStyle(fontSize: 12, fontFamily: 'FangSong', fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312']),
      ),
      // 底部导航栏主题
      bottomNavigationBarTheme: BottomNavigationBarThemeData(
        backgroundColor: Colors.white,
        selectedItemColor: colorSeed,
        unselectedItemColor: Colors.grey.shade600,
        selectedIconTheme: IconThemeData(size: 24, color: colorSeed),
        unselectedIconTheme: IconThemeData(size: 22, color: Colors.grey.shade600),
        showSelectedLabels: true,
        showUnselectedLabels: true,
        type: BottomNavigationBarType.fixed,
        elevation: 8,
      ),
      // NavigationBar主题
      navigationBarTheme: NavigationBarThemeData(
        backgroundColor: Colors.white,
        indicatorColor: colorSeed.withOpacity(0.1),
        labelTextStyle: MaterialStateProperty.resolveWith((states) {
          if (states.contains(MaterialState.selected)) {
            return const TextStyle(
              fontFamily: 'FangSong',
              fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312'],
              fontWeight: FontWeight.bold,
              fontSize: 14,
            );
          }
          return const TextStyle(
            fontFamily: 'FangSong',
            fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312'],
            fontWeight: FontWeight.bold,
            fontSize: 12,
          );
        }),
        iconTheme: MaterialStateProperty.resolveWith((states) {
          if (states.contains(MaterialState.selected)) {
            return IconThemeData(size: 24, color: colorSeed);
          }
          return IconThemeData(size: 22, color: Colors.grey.shade600);
        }),
        elevation: 3,
      ),
      // 分割线主题
      dividerTheme: DividerThemeData(
        color: Colors.grey.shade200,
        thickness: 1,
        space: 1,
      ),
      // 滑块主题
      sliderTheme: SliderThemeData(
        activeTrackColor: colorSeed,
        inactiveTrackColor: colorSeed.withOpacity(0.2),
        thumbColor: colorSeed,
        overlayColor: colorSeed.withOpacity(0.2),
        valueIndicatorColor: colorSeed,
        valueIndicatorTextStyle: const TextStyle(color: Colors.white),
      ),
    );
  }
  
  // 获取暗色主题
  static ThemeData darkTheme({int colorSeedIndex = 0}) {
    final colorSeed = colorSeeds[colorSeedIndex % colorSeeds.length];
    final darkColorSeed = HSLColor.fromColor(colorSeed)
        .withLightness((HSLColor.fromColor(colorSeed).lightness + 0.2).clamp(0.0, 1.0))
        .toColor();
    
    return ThemeData(
      useMaterial3: true,
      colorScheme: ColorScheme.fromSeed(
        seedColor: colorSeed,
        brightness: Brightness.dark,
      ),
      scaffoldBackgroundColor: const Color(0xFF121212),
      // 应用栏主题
      appBarTheme: AppBarTheme(
        centerTitle: true,
        elevation: 2,
        shadowColor: Colors.black.withOpacity(0.3),
        backgroundColor: const Color(0xFF1E1E1E),
        foregroundColor: darkColorSeed,
        iconTheme: IconThemeData(color: darkColorSeed),
        titleTextStyle: TextStyle(
          fontSize: 18,
          fontWeight: FontWeight.bold,
          color: darkColorSeed,
        ),
      ),
      // 卡片主题
      cardTheme: CardThemeData(
        elevation: 4,
        shadowColor: Colors.black.withOpacity(0.4),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(16),
        ),
        clipBehavior: Clip.antiAlias,
        color: const Color(0xFF242424),
      ),
      // 按钮主题
      elevatedButtonTheme: ElevatedButtonThemeData(
        style: ElevatedButton.styleFrom(
          padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10),
          ),
          elevation: 3,
          shadowColor: darkColorSeed.withOpacity(0.4),
          backgroundColor: darkColorSeed.withOpacity(0.8),
          foregroundColor: Colors.white,
        ),
      ),
      // 文本按钮主题
      textButtonTheme: TextButtonThemeData(
        style: TextButton.styleFrom(
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(8),
          ),
          foregroundColor: darkColorSeed,
        ),
      ),
      // 输入框主题
      inputDecorationTheme: InputDecorationTheme(
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(10),
          borderSide: BorderSide(color: Colors.grey.shade700),
        ),
        enabledBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(10),
          borderSide: BorderSide(color: Colors.grey.shade700),
        ),
        focusedBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(10),
          borderSide: BorderSide(color: darkColorSeed, width: 2),
        ),
        filled: true,
        fillColor: const Color(0xFF2A2A2A),
        contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
        hintStyle: TextStyle(color: Colors.grey.shade500),
      ),
      // 文本主题 - 使用仿宋字体
      textTheme: TextTheme(
        titleLarge: TextStyle(fontWeight: FontWeight.bold, fontSize: 22, color: Colors.grey.shade200, fontFamily: 'FangSong', fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312']),
        titleMedium: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Colors.grey.shade200, fontFamily: 'FangSong', fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312']),
        titleSmall: TextStyle(fontWeight: FontWeight.bold, fontSize: 16, color: Colors.grey.shade300, fontFamily: 'FangSong', fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312']),
        bodyLarge: TextStyle(fontSize: 16, color: Colors.grey.shade300, fontFamily: 'FangSong', fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312']),
        bodyMedium: TextStyle(fontSize: 14, color: Colors.grey.shade400, fontFamily: 'FangSong', fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312']),
        bodySmall: TextStyle(fontSize: 12, color: Colors.grey.shade400, fontFamily: 'FangSong', fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312']),
      ),
      // 底部导航栏主题
      bottomNavigationBarTheme: BottomNavigationBarThemeData(
        backgroundColor: const Color(0xFF1E1E1E),
        selectedItemColor: darkColorSeed,
        unselectedItemColor: Colors.grey.shade500,
        selectedIconTheme: IconThemeData(size: 24, color: darkColorSeed),
        unselectedIconTheme: IconThemeData(size: 22, color: Colors.grey.shade500),
        showSelectedLabels: true,
        showUnselectedLabels: true,
        type: BottomNavigationBarType.fixed,
        elevation: 8,
      ),
      // NavigationBar主题
      navigationBarTheme: NavigationBarThemeData(
        backgroundColor: const Color(0xFF1E1E1E),
        indicatorColor: darkColorSeed.withOpacity(0.2),
        labelTextStyle: MaterialStateProperty.resolveWith((states) {
          if (states.contains(MaterialState.selected)) {
            return TextStyle(
              fontFamily: 'FangSong',
              fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312'],
              fontWeight: FontWeight.bold,
              fontSize: 14,
              color: Colors.grey.shade200,
            );
          }
          return TextStyle(
            fontFamily: 'FangSong',
            fontFamilyFallback: ['仿宋', 'FangSong', 'FangSong_GB2312'],
            fontWeight: FontWeight.bold,
            fontSize: 12,
            color: Colors.grey.shade400,
          );
        }),
        iconTheme: MaterialStateProperty.resolveWith((states) {
          if (states.contains(MaterialState.selected)) {
            return IconThemeData(size: 24, color: darkColorSeed);
          }
          return IconThemeData(size: 22, color: Colors.grey.shade500);
        }),
        elevation: 3,
      ),
      // 分割线主题
      dividerTheme: DividerThemeData(
        color: Colors.grey.shade800,
        thickness: 1,
        space: 1,
      ),
      // 滑块主题
      sliderTheme: SliderThemeData(
        activeTrackColor: darkColorSeed,
        inactiveTrackColor: darkColorSeed.withOpacity(0.3),
        thumbColor: darkColorSeed,
        overlayColor: darkColorSeed.withOpacity(0.3),
        valueIndicatorColor: darkColorSeed,
        valueIndicatorTextStyle: const TextStyle(color: Colors.white),
      ),
    );
  }
}